<?php
class adsModel extends commonModel
{
    public function __construct()
    {
        parent::__construct();
    }

    //获取广告列表
    public function ads_list() {
        return $this->model->table('ads')->order('id asc')->select();
    }
    //获取广告内容
    public function info($id)
    {
        return $this->model->table('ads')->where('id='.$id)->find();
    }

    //添加广告内容
    public function add($data)
    {
       	if($_POST['photofile']){
			$photonum=$_POST['photonum'];
			$photofile=$_POST['photofile'];
			$photourl=$_POST['photourl'];
			$phototxt=$_POST['phototxt'];$ns='';
			natsort($photonum);
			foreach($photonum as $k=>$v){
				$ns.='|-|'.$photofile[$k].'|,|'.$phototxt[$k].'|,|'.$photourl[$k];
			}
			$photo=substr($ns,3);
		}
	    $data['adfile']=$photo;
	    $data['body']=html_in($data['body']);
        return $this->model->table('ads')->data($data)->insert();
    }

    //编辑广告内容
    public function edit($data)
    {
        $condition['id']=intval($data['id']);
       	if($_POST['photofile']){
			$photonum=$_POST['photonum'];
			$photofile=$_POST['photofile'];
			$photourl=$_POST['photourl'];
			$phototxt=$_POST['phototxt'];$ns='';
			natsort($photonum);
			foreach($photonum as $k=>$v){
				$ns.='|-|'.$photofile[$k].'|,|'.$phototxt[$k].'|,|'.$photourl[$k];
			}
			$photo=substr($ns,3);
		}
	    $data['adfile']=$photo;
        $data['body']=html_in($data['body']);
        return $this->model->table('ads')->data($data)->where($condition)->update(); 
    }

    //删除广告内容
    public function del($id)
    {
        return $this->model->table('ads')->where('id='.intval($id))->delete(); 
    }

}

?>